function [dataout]=dataprepnew(V,E)

% takes as input the output of the function budgetset, a square vector
% which takes the entry (i,j) takes the value one if the choice made in
% trial i is in the budget set used in trial j
% 

% Gives as output data of the form that can be used by the houtman maks
% program which is a list of the form 
% With click 32, subject 41 selected item 19 from 19, 22, 24, and 23
%     22 19 32 
%     24 19 32 
%     23 19 32 

trials=length(V);
a=1:trials;

%available is a matrixs containing the objects that are in the buget set in
%each trial
available=V.*(a'*ones(1,trials));

%set diagoanal elements to zero 
a=diag(ones(trials,1),0);
a=a==0;
available=available.*a;

%counter is the number of objects that the chosen object is revealed
%preferred to in each trial
counter=sum(V)-1;
available=sort(available);

%constructs the dataout matrix
dataout(1:counter(1),1)=available((trials-counter(1)+1):trials,1);
dataout(1:counter(1),2)=1;
dataout(1:counter(1),3)=E(available((trials-counter(1)+1):trials,1),1);
for count=2:trials
    clear package;
package(1:counter(count),1)=available((trials-counter(count)+1):trials,count);
package(1:counter(count),2)=count;
package(1:counter(count),3)=E(available((trials-counter(count)+1):trials,count),count);
dataout=[dataout;package];
end

end